package com.k7k7.sserver.config;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2009-4-21
 * Time: 17:35:17
 */
public class SceneServerConfig {
	public static Integer clientPort = 9999;//对客户端的服务端口
	public static String controlServerAddress = "localhost";//总控服务器的地址
	public static Integer controlServerPort = 10000;//总控服务器的端口

	public static void getConfig(String args) {
		if (args != null && !(args.trim().equals(""))) {
			File configFile = new File(args);
			try {
				BufferedReader br = new BufferedReader(new FileReader(configFile));
				StringBuffer sb = new StringBuffer();
				String s;
				while ((s = br.readLine()) != null) {
					sb.append(s);
				}
				Document doc = DocumentHelper.parseText(sb.toString());
				clientPort = Integer.valueOf(doc.getRootElement().elementText("client-port"));
				controlServerAddress = doc.getRootElement().elementText("server-address");
				controlServerPort = Integer.valueOf(doc.getRootElement().element("server-port").getText());
			} catch (Exception e) {
				System.out.println("读取配置错误！");
			}

		}

	}
}